package com.dragon.repository.domain.vo;

import com.dragon.common.model.Update;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Repair;
import com.dragon.repository.entity.RepairProduct;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@ApiModel(value = "")
public class RepairVO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @ApiModelProperty(value = "维修名称")
    @NotNull(message = "维修名称不能为空")
    private String repairName;

    @ApiModelProperty(value = "生产单id")
    private Integer produceId;

    @ApiModelProperty(value = "退货单id")
    private Integer rejectId;

    @ApiModelProperty(value = "维修人")
    private Integer adminId;

    @ApiModelProperty(value = "维修部门")
    private Integer departmentId;

    @ApiModelProperty(value = "维修备注")
    private String remark;

    @ApiModelProperty(value = "维修单状态：0、待维修，1、维修完成")
    private Integer status;

    @ApiModelProperty(value = "送货标识:0、未完成，1、已完成")
    private Integer deliver;

    @ApiModelProperty(value = "合同id")
    @NotNull(message = "合同不能为空")
    private Integer contractId;

    @ApiModelProperty(value = "预计完成维修时间")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date deadline;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "维修产品")
    @NotNull(message = "维修产品不能为空")
    private List<RepairProductVO> repairProducts;


    @NotNull(groups = Update.class,message = "主键不能为空")
    public static Repair convert(RepairVO vo) {
        Repair entity = new Repair();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }
    public static List<Repair> convertList(List<RepairVO> list) {
        List<Repair> resultList = new ArrayList<>();
        for (RepairVO vo : list) {
            resultList.add(convert(vo));
        }
        return resultList;
    }
}
